<?php
	namespace Common\Logic;
    use Common\Model\StoresWorkerListModel;

    class StoresWorkerListLogic extends StoresWorkerListModel {
		/*
		* Function:		getStoresList
		* Description:	门店列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getStoresWorkerListList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getStoresWorkerListFilter($filter);
			return $this->where($conditon)->order('sort desc,id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getStoresFilter
		* Description:	门店列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getStoresWorkerListFilter($filter = ''){
			$conditon = array();
			$conditon['is_deleted'] = 0;
			if(!empty($filter['title'])){
				$conditon['title'] = array('like','%'.$filter['title'].'%');
			}
			if(!empty($filter['province_name'])){
			    $info = M('regions')->where(['local_name'=>$filter['province_name'],'region_grade'=>1])->find();
			    $conditon['province_id'] = $info['region_id'];
			}
			if(!empty($filter['status'])){
			    $conditon['status'] = $filter['status'];
			}
            if(!empty($filter['role'])){
                $conditon['role'] = $filter['role'];
            }
			return $conditon;
		}
		
		/*
		* Function:get:	getStoresCount
		* Description:	门店列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getStoresWorkerListCount($filter = ''){
			$conditon = $this->getStoresWorkerListFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addStores
		* Description:	增加门店
		* @param:		$data array 增加的数组
		*/
		public function addStoresWorkerList($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getStoresInfo
		* Description:	获取门店信息 by row
		* @param:		$id int ID
		*/
		public function getStoresWorkerListInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateStores
		* Description:	更新门店
		* @param:		$data array 更新的数组
		*/
		public function updateStoresWorkerList($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteStores
		* Description:	删除门店
		* @param:		$id int ID
		*/
		public function deleteStoresWorkerList($id){
			return $this->where(array('id'=>$id))->delete();
		}
		
		/*
		* Function:		getStoresAllList
		* Description:	部门列表
		*/
		public function getStoresWorkerListAllList(){
			return $this->where(array('status'=>1))->select();
		}
	}
?>